﻿using Factory.Common;
using Factory.RBAC;
using Factory.RBAC.Permissions;
using Factory.RBAC.Permissions.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Factory.Web.Controllers.RBAC
{
    public class PermissionController : Controller
    {
        /// <summary>
        /// 权限接口
        /// </summary>
        private readonly IPermissionsAppService _permissionService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="permissionService"></param>
        public PermissionController(IPermissionsAppService permissionService)
        {
            _permissionService = permissionService;
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 树形权限
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<TreePermissionDto>> TreePermission()
        {
            var treePermission =await _permissionService.TreePermission();
            return treePermission;
        }


        /// <summary>
        /// 获取具体数据进行反填
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Permission> GetPermission(int id)
        {
            var permission = await _permissionService.GetPermission(id);
            return permission;
        }



        /// <summary>
        /// 添加权限
        /// </summary>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<int> AddSon(Permission permission)
        {
            var i = await _permissionService.AddSon(permission);
            return i;
        }

        /// <summary>
        /// 添加同集权限
        /// </summary>
        /// <returns>返回受影响行数</returns>
        public async Task<int> AddEquality(Permission permission)
        {
            var i = await _permissionService.AddEquality(permission);
            return i;
        }


        /// 修改权限
        /// </summary>
        /// <returns>返回受影响行数</returns>
        public async Task<int> AddUpdate(PermissionDto permission)
        {
            var i = await _permissionService.AddUpdate(permission);
            return i;
        }



    }
}
